<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class Headbar{

	private $header;
	private $menu;

	public function __construct(){
		$this->CI =& get_instance();
	}

	public function is_set(){
		if(isset($this->header) || isset($this->menu)) 
			return true;
		else return false;
	}

	public function add_header($heading = ''){

		if($heading == ''){

			$kelas = $this->CI->uri->segment(1);
			$fungsi = $this->CI->uri->segment(2);

			if($fungsi != '' && $fungsi != 'index')
				$this->header = anchor($kelas,ucfirst($kelas)).' > '.ucfirst($fungsi);
			else $this->header = ucfirst($kelas);

		} else {

			$this->header = $heading;

		}

		return $this;
	}

	public function add_menu($id,$label,$link = ''){
		$this->menu[$id] = array($label,$link);
		return $this;
	}

	public function __toString(){

		$string = '<div id="headBar">';

		if(isset($this->header))
			$string .= heading($this->header,2);

		if(isset($this->menu)){

			$string .= '<div id="headMenu">';
			foreach ($this->menu as $id => $data) {
				$string .= anchor($data[1],$data[0],'id = '.$id.'_menu');
			} 
			$string .= '</div>';

		}

		$string .= '</div>';

		if($this->CI->session->flashdata('status')){ 
			$flash = $this->CI->session->flashdata('status');
			$string .= "<div id='flash_info'> $flash </div>";
		}

		return $string;
	}
}
